<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function addEvent(){
            $("myImg").onclick = function (){
                alert("我被点了");
            }
        }
        function cancelEvent(){
            $("myImg").onclick = null;
        }

        function $(id){
            return document.getElementById(id);
        }
    </script>
</head>
<body>
    <input type="button" value="添加事件" onclick="addEvent()">
    <input type="button" value="取消事件" onclick="cancelEvent()"><br>
    <img src="img/3.jpg" width="300" height="300" id="myImg">

    <!--    如果一个事件函数返回值为false，可以阻止元素默认行为-->
    <form action="ddd">
        姓名：<input type="text" name="userName" onpaste="return false"
                  onkeypress="return false"><br>
        <input type="submit" value="提交" onclick="return false">
    </form>



</body>
</html>